home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
pcl4c60.zip
/
SIMPLE32.C
< prev
next >
Wrap
Text File
|
1996-10-24
|
3KB
|
121 lines
/* simple32.c */
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <dos.h>
#include <string.h>
#include <conio.h>
#include "pcl4c32.h"
#include "sioerr32.h"
#ifndef FALSE
#define FALSE 0
#define TRUE !FALSE
#endif
/*** Global Variables ***/
int Port = COM1; /* Port COM1 */
int BaudCode; /* baud rate code ( index into BaudRate[] ) */
char *BaudRate[10] = {"300","600","1200","2400","4800","9600",
"19200","38400","57600","115200"};
long hRxMem;
long hTxMem;
long hMemory;
int Version;
/*** local prototypes */
int BaudMatch(char *);
int ErrorCheck(int);
/*** main ***/
void main(int argc, char *argv[])
{char c;
int i, rc;
if(argc!=3)
{printf("Usage: SIMPLE32 <port> <baud>\n");
exit(1);
}
/* get port number from command line */
Port = atoi(argv[1]) - 1;
if((Port<COM1) || (Port>COM4))
{printf("Port must be COM1 to COM4\n");
exit(1);
}
/* get baud rate from command line */
BaudCode = BaudMatch(argv[2]);
if(BaudCode<0)
{printf("Cannot recognize baud rate = %s\n",argv[2]);
exit(1);
}
/* setup 1024 byte receive buffer */
ErrorCheck( SioRxBuf(Port,0,Size1024) );
/* setup 128 byte transmit buffer */
ErrorCheck( SioTxBuf(Port,0,Size128) );
/* reset the port */
printf("Resetting COM%d: ",1+Port);
ErrorCheck( SioReset(Port,BaudCode) );
printf("Port reset\n");;
/* set DTR and RTS */
ErrorCheck( SioDTR(Port,'S') );
ErrorCheck( SioRTS(Port,'S') );
#if 0
/* set RTS/CTS flow control */
ErrorCheck( SioFlow(Port,18) );
puts("Flow control on");
#endif
/* Set FIFO level */
if(SioFIFO(Port,LEVEL_8)) printf("[16550]\n");
else printf("[8250/16450]");
printf("\nEnter terminal loop ( Type ^Z to exit )\n");
/* enter terminal loop */
while(TRUE)
{/* was key pressed ? */
if(kbhit())
{i = getch();
if((char)i==0x1a)
{/* restore COM port status & exit */
SioDone(Port);
puts("DONE.");
exit(1);
}
else SioPutc(Port,(char)i);
} /* end if */
/* any incoming over serial port ? */
i = SioGetc(Port,0);
ErrorCheck(i);
if(i>-1) putch((char)i);
} /* end while */
} /* end main */
int ErrorCheck(int Code)
{/* trap PCL error codes */
if(Code<-1)
{printf("ERROR %d: ",Code);
SioError(Code);
SioDone(Port);
exit(1);
}
return(Code);
} /* end ErrorCheck */
int BaudMatch(char *P)
{int i;
/* find baud rate in table */
for(i=0;i<10;i++) if(strcmp(BaudRate[i],P)==0) return(i);
return(-1);
}